import { IsIn, IsInt, IsNotEmpty, IsOptional, IsString, MaxLength } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { DICT_STATUS_VALUES, type ICreateDict } from '@nbase/shared';
import { Type } from 'class-transformer';

/**
 * 创建字典 DTO
 */
export class CreateDictDto implements ICreateDict {
  @ApiProperty({ description: '字典编码', example: 'user_status' })
  @IsString()
  @IsNotEmpty()
  @MaxLength(128)
  code!: string;

  @ApiProperty({ description: '字典名称', example: '用户状态' })
  @IsString()
  @IsNotEmpty()
  @MaxLength(128)
  name!: string;

  @ApiPropertyOptional({
    description: '状态（1.启用 2.禁用）',
    example: 1,
    enum: DICT_STATUS_VALUES,
  })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @IsIn(DICT_STATUS_VALUES)
  status?: number;

  @ApiPropertyOptional({ description: '描述', example: '用户状态字典' })
  @IsOptional()
  @IsString()
  @MaxLength(256)
  description?: string;
}

